package com.hqj.controller;

import com.hqj.entity.Comment;
import com.hqj.service.CommentService;
import com.hqj.utils.ResultUtil;
import com.hqj.utils.ResultVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 黄啟军
 * @version 1.0
 * @date 2020/8/2 0002
 */
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Resource
    private CommentService commentService;
    @ApiOperation("添加评论")
    @PostMapping("/saveComment")
    public ResultVO<String> saveComment(@RequestBody Comment comment){
        int i = commentService.saveComment(comment);
        if(i>0){
            return ResultUtil.success("添加成功");
        }
        return ResultUtil.error();
    }
    @ApiOperation("查询评论")
    @GetMapping("/selectAll/{id}")
    public ResultVO<List<Comment>> selectAll(@PathVariable("id") Long id){
        List<Comment> comments =
                commentService.selectAll(id);
        if (comments.isEmpty()){
            return ResultUtil.error();
        }
        return ResultUtil.success(comments);
    }
}
